﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AssettDatabase
{
    public partial class Form_Add_Supplier : Form
    {
        public Form_Add_Supplier()
        {
            InitializeComponent();
        }

        private void Add_Supplier_Load(object sender, EventArgs e)
        {

        }

        private void Btn_Return_Main_Click(object sender, EventArgs e)
        {
            this.Dispose();
            FormProvider.MainMenu.Show();
        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void textBox9_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void textBox8_TextChanged(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Lbl_Supplier_Name_Click(object sender, EventArgs e)
        {

        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {

        }

        private void AS_BT_Add_Supplier_Click(object sender, EventArgs e)
        {
         try
            {
                if (AS_TB_Supplier_Name.Text.Length == 0)
                {
                    MessageBox.Show("Supplier Name is a mandatory field.");
                    return;
                }
                if (AS_TB_Supplier_Phone.Text.Length == 0)
                {
                    MessageBox.Show("Supplier Phone is a mandatory field.");
                    return;
                }
                if (AS_TB_Website.Text.Length == 0)
                {
                    MessageBox.Show("Website is a mandatory field.");
                    return;
                }
                if (AS_TB_Supplier_Code.Text.Length == 0)
                {
                    MessageBox.Show("Supplier Customer Code is a mandatory field.");
                    return;
                }

                BLL.Supplier supplier = new BLL.Supplier();
                if (!supplier.Add(AS_TB_Supplier_Name.Text, AS_TB_Supplier_Phone.Text, AS_TB_Contact_FN.Text, AS_TB_Contact_LN.Text, AS_TB_Contact_EML.Text,
                           AS_TB_Website.Text, AS_TB_Website_Login.Text, AS_TB_Website_Password.Text, AS_TB_Supplier_Code.Text, AS_TB_Supplier_Comments.Text))
                    MessageBox.Show("An error occurred during supplier insert");
                else
                    MessageBox.Show(AS_TB_Supplier_Name.Text + " has been added to the Assett Database");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void Form_Add_Supplier_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Dispose();
            FormProvider.MainMenu.Show();
        }
    }
}